package jp.ac.waseda.cs.washi.game;

import jp.ac.waseda.cs.washi.game.api.CharaInfo;
import jp.ac.waseda.cs.washi.gameaiarena.api.Direction4;
import jp.ac.waseda.cs.washi.game.api.MapInfo;
import jp.ac.waseda.cs.washi.gameaiarena.api.Point2;
import jp.ac.waseda.cs.washi.game.entity.Chara;
import jp.ac.waseda.cs.washi.game.entity.Map;

public final class MoveManager {

	private MoveManager() {
	}

	static void moveChara(Map map, Chara chara, Direction4 direction) {

		chara.changeDirection(direction);
		if (!isMovable(map.getInfo(), chara.getInfo(), direction))
			return;
		chara.move(direction);
	}

	public static boolean isMovable(MapInfo map, CharaInfo chara,
			Direction4 direction) {
		return isMovable(map, chara.getLocation().move(direction));
	}

	public static boolean isMovable(MapInfo map, Point2 p) {
		return map.isAvailable(p) && !map.isWall(p);
	}
}
